# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=ffts
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.0.r799.gfe86885
pkgrel=2
pkgdesc="ffts: The Fastest Fourier Transform in the South  (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/anthonix/ffts"
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
_commit='fe86885e'
source=("${_realname}::git+https://github.com/anthonix/ffts.git#commit=${_commit}"
        "0001-CMake-Pretend-clang-is-gcc.patch"
        "0002-CMake-Install-dll-in-bindir.patch"
        "0003-CMake-Install-pkgconfig-file.patch")
sha256sums=('SKIP'
            '8a93db6b71231d0483cc5a4f9e2ed615779034c837e7956850d4d1cb46b5ba01'
            '44bc988f91837096fc161223a7df8338e5574ace0e0c947a945370066e84f453'
            '9fc99e4ffe5dfb06a455bb71ffe742b2877c6ce07e9a72fc0e75d4920c6c61ec')

pkgver() {
  cd "${_realname}"
  echo '0.0.0.r'"$(git rev-list --count "${_commit}")"'.g'"$(git describe --all --long "${_commit}" | sed 's/^.*-g\(.*\)/\1/')"
}

prepare() {
  cd "${_realname}"
  git am --committer-date-is-author-date "${srcdir}/0001-CMake-Pretend-clang-is-gcc.patch"
  git am --committer-date-is-author-date "${srcdir}/0002-CMake-Install-dll-in-bindir.patch"
  git am --committer-date-is-author-date "${srcdir}/0003-CMake-Install-pkgconfig-file.patch"
}

build() {
  cd "${srcdir}/${_realname}"
  mkdir build
  cd build
  MSYS2_ARG_CONV_EXCL=-DCMAKE_INSTALL_PREFIX= cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DENABLE_SHARED=ON \
    ../
  cmake --build .
}

package() {
  cd "${srcdir}/${_realname}"/build
  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}/COPYRIGHT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT"
}
